package cn.taketoday.live.handler;

import com.alibaba.fastjson.JSONObject;

import java.io.IOException;

import cn.taketoday.live.data.JsonSequence;
import cn.taketoday.live.data.enums.ShieldMessage;

/**
 * @author TODAY 2021/5/17 22:31
 */
public class CommandContext {
  private final JSONObject original;
  private final MessageHandler messageHandler;

  public CommandContext(JSONObject original, MessageHandler messageThread) {
    this.original = original;
    this.messageHandler = messageThread;
  }

  public JSONObject getOriginal() {
    return original;
  }

  public MessageHandler getMessageHandler() {
    return messageHandler;
  }

  public void sendMessage(String message) throws IOException {
    messageHandler.getWebsocket().sendMessage(message);
  }

  public void sendMessage(JsonSequence message) throws IOException {
    messageHandler.getWebsocket().sendMessage(message.toJSON());
  }

  public boolean contains(ShieldMessage shieldMessage) {
    final Boolean aBoolean = messageHandler.getMessageControlMap().get(shieldMessage);
    return aBoolean != null && aBoolean;
  }

}
